/*
 * Lombo SoC reset code
 *
 * Copyright (C) 2016-2018, LomboTech Co.Ltd.
 * Author: lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/io.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/reboot.h>
#include <mach/lombo_watchdog.h>

#include "lombo-reboot.h"

static int lombo_restart_handler(struct notifier_block *this,
				unsigned long mode, void *cmd)
{
#ifdef CONFIG_ARCH_LOMBO_N7V1
	#ifdef CONFIG_RTC_LOMBO
	if (cmd) {
		if (strcmp(cmd, "pol") == 0)
			lombo_set_sys_stat();
	}
	#endif
#else
	#ifdef CONFIG_LOMBO_POWER_MANAGER
	if (cmd) {
		if (strcmp(cmd, "pol") == 0)
			lombo_set_sys_stat();
	}
	#endif
#endif

	lombo_wdt_restart(REBOOT_HARD, cmd);

	return NOTIFY_DONE;
}

static struct notifier_block lombo_restart_nb = {
	.notifier_call = lombo_restart_handler,
	.priority = 128,
};

static int lombo_reboot_probe(struct platform_device *pdev)
{
	int err;

	err = register_restart_handler(&lombo_restart_nb);
	if (err)
		PRT_ERR("cannot register restart handler (err=%d)\n", err);

	return err;
}

static const struct of_device_id lombo_reboot_of_match[] = {
	{ .compatible = "lombotech,reset" },
	{}
};

static struct platform_driver lombo_reboot_driver = {
	.probe = lombo_reboot_probe,
	.driver = {
		.name = "lombo-reboot",
		.of_match_table = lombo_reboot_of_match,
	},
};
module_platform_driver(lombo_reboot_driver);

MODULE_AUTHOR("lomboswer@lombotech.com");
MODULE_DESCRIPTION("Driver for LomboTech reset");
MODULE_LICENSE("GPL");
